﻿using System;
using System.Diagnostics;
using System.IO;
using Chess.Common.Network;
using NUnit.Framework;
using Version = Chess.Common.Network.Version;

namespace Common.Test
{
    [TestFixture]
    public sealed class Network
    {
        [Test]
        public void SerializedReaderWriter()
        {
            using (MemoryStream stream = new MemoryStream())
            {
                StreamWriter writer = new StreamWriter(stream);
                StreamReader reader = new StreamReader(stream);

                INetworkWriter networkWriter = new SerializedNetworkWriter(writer);
                INetworkReader networkReader = new SerializedNetworkReader(reader);

                HandshakePacket sendPacket = new HandshakePacket(new Version(1, 2, 3));
                HandshakePacket recvPacket;

                networkWriter.Write(sendPacket);

                stream.Position = 0;
                recvPacket = (HandshakePacket)networkReader.Read();

                Assert.IsTrue(recvPacket.Id.Equals(sendPacket.Id));
                Assert.IsTrue(recvPacket.Version.Equals(sendPacket.Version));
            }
        }
    }
}
